package com.macro.utils;

import java.util.HashMap;

/**
 * 操作消息提醒
 */
public class AjaxResponse extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    /** 状态码 */
    public static final String CODE_TAG = "code";

    /** 返回内容 */
    public static final String MSG_TAG = "msg";

    /** 数据对象 */
    public static final String DATA_TAG = "data";

    /**
     * 初始化一个新创建的 AjaxResult 对象，使其表示一个空消息。
     */
    public AjaxResponse()
    {
    }

    /**
     * 初始化一个新创建的 AjaxResult 对象
     *
     * @param code 状态码
     * @param msg 返回内容
     */
    public AjaxResponse(int code, String msg)
    {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
    }

    public AjaxResponse(int code, Object object)
    {
        super.put(CODE_TAG, code);
        super.put(DATA_TAG, object);
    }

    public AjaxResponse(Object object)
    {
        super.put(DATA_TAG, object);

    }

    /**
     * 初始化一个新创建的 AjaxResult 对象
     *
     * @param code 状态码
     * @param msg 返回内容
     * @param data 数据对象
     */
    public AjaxResponse(int code, String msg, Object data)
    {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
    }

    public static AjaxResponse success()
    {
        return new AjaxResponse(ResponseCode.SUCCESS.getCode(), null);
    }

    public static AjaxResponse nofind(String msg)
    {
        return new AjaxResponse(ResponseCode.NOFIND.getCode(), msg);
    }

    public static AjaxResponse error()
    {
        return new AjaxResponse(ResponseCode.ERROR.getCode(), null);
    }

    public static AjaxResponse success(Object object)
    {
        return new AjaxResponse(ResponseCode.SUCCESS.getCode(),object);
    }

    public static AjaxResponse success(Integer code,String msg)
    {
        return new AjaxResponse(code, msg);
    }

    public static AjaxResponse success(Integer code,Object msg)
    {
        return new AjaxResponse(code, msg);
    }

    public static AjaxResponse error(String msg)
    {
        return new AjaxResponse(ResponseCode.ERROR.getCode(), msg);
    }

    public static AjaxResponse error(Object object)
    {
        return new AjaxResponse(object);
    }

    public static AjaxResponse error(int code,String msg)
    {
        return new AjaxResponse(code, msg);
    }

    public static AjaxResponse messageResult(String msg)
    {
        return new AjaxResponse(ResponseCode.SUCCESS.getCode(), msg);
    }

    public static AjaxResponse messageResult(Integer code,String msg)
    {
        return new AjaxResponse(code, msg);
    }


}